package com.rankeiot.developer.controller;

import com.rankeiot.core.anno.interceptor.AuthInterceptor;
import com.rankeiot.core.data.response.Resp;
import com.rankeiot.core.inner.argumet.QueryPage;
import com.rankeiot.core.inner.argumet.QueryParams;
import com.rankeiot.developer.domain.TableMeta;
import com.rankeiot.developer.modules.TableMetaModule;
import com.rankeiot.developer.service.TableServices;
import lombok.RequiredArgsConstructor;
import org.sagacity.sqltoy.dao.LightDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("model/{modeId}")
@RequiredArgsConstructor
public class ModelController {
    private final TableMetaModule tableMetaModule;

    @GetMapping("meta")
    public Resp meta(@PathVariable String modeId) {
        return Resp.of(tableMetaModule.get(modeId).getViewModel());
    }

    @PostMapping("page")
    public Resp page(@PathVariable String modeId, QueryPage query) {
        TableServices.TableModel meta = tableMetaModule.get(modeId);
        TableServices.DataModel dm = meta.getDataModel();
        //权限判断
        // meta.getMeta().getAuthList();
        return Resp.of(dm.loadPage(query.page(), query.params()));
    }

    public Resp detail(@PathVariable String modeId, QueryParams query) {
        TableServices.TableModel meta = tableMetaModule.get(modeId);
        TableServices.DataModel dm = meta.getDataModel();
        return Resp.of(dm.detail(query.params()));
    }

    public void create() {

    }

    public void save() {

    }

    public void delete() {

    }

    public void importData() {

    }

    public void exportData() {

    }
}
